<?php

namespace app\api\controller;

use app\api\BaseController;
use app\api\extend\firebase\Jwt;
use app\model\UserModel;
use GuzzleHttp\Client;

class User extends BaseController
{
    public function login()
    {
        $params = $this->request->param();

        $userModel = UserModel::where([
            'username' => $params['username'],
            'status' => 0
        ])->find();

        if ($userModel === null) {
            return show(code: 1, message:'用户名或密码错误');
        }

        if (password_verify($params['password'], $userModel->password) === false) {
            return show(code: 1, message:'用户名或密码错误');
        }

        $jwt = new Jwt();
        $token = $jwt->encrypt([
            'userId' => $userModel->id
        ]);
        return show([
            'token' => $token
        ]);
    }

}